﻿using Autofac.Core;
using MediatR;
using SheepStorage.API.Application.Command.BodySizeCommand;
using SheepStorage.API.Application.Command.BuildingManagementCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.BodySizeHandler
{
    public class BodySizeUpdaHandler : IRequestHandler<BodySizeUpdaCommand, Results<int>>
    {

        private readonly IBodySizeService service;

        public BodySizeUpdaHandler(IBodySizeService service)
        {
            this.service = service;
        }
        public async Task<Results<int>> Handle(BodySizeUpdaCommand request, CancellationToken cancellationToken)
        {
            var entity = new BodySize
            {
                BodySizeId = request.BodySizeId,
                OverBit = request.OverBit,
                SheepType = request.SheepType,
                BodySex = request.BodySex == 1 ? true : false,
                CheckDate = request.CheckDate,
                BodyHeight = request.BodyHeight,
                BodyLength = request.BodyLength,
                BodyThorax = request.BodyThorax,
                BodyFoot = request.BodyFoot,
                BodyScrotum = request.BodyScrotum,
                BodyBackWeight = request.BodyBackWeight,
                BodyEyeArea = request.BodyEyeArea,
                BodyEyeWeight = request.BodyEyeWeight,
                UpdateName="杨博",
                UpdateTime=DateTime.Now,
                IsDel=0,
            };
            var list = await service.UpdaBodySize(entity);
            return Results<int>.DataResult(list);
        }
    }
}
